package com.seewo.dubbo.debugger.admin.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.seewo.dubbo.debugger.admin.common.validate.group.Query;
import com.seewo.dubbo.debugger.admin.common.validate.group.Update;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author chenliangliang
 * @since 2018-07-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_registry")
public class Registry implements Serializable {

    private static final long serialVersionUID = 214349785490151213L;

    @TableId(value = "c_id", type = IdType.AUTO)
    @NotNull(message = "注册中心id不能为空", groups = {Update.class})
    @Min(message = "cid不合法", value = 0, groups = {Update.class})
    private Integer cId;
    @NotBlank(message = "要更新的注册中心名不能为空", groups = {Update.class})
    private String cName;
    @NotBlank(message = "协议不能为空", groups = {Query.class})
    private String cProtocol;
    @NotBlank(message = "链接地址不能为空", groups = {Query.class})
    @Pattern(regexp = "(\\d|[1-9]\\d|1\\d{2}|2[0-5][0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-5][0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-5][0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-5][0-5]):([0-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-5]{2}[0-3][0-5])",
            message = "ip:port格式错误", groups = {Query.class})
    private String cAddress;
    @JSONField(serialize = false, deserialize = false)
    private Date cCreateTime;
    @JSONField(serialize = false, deserialize = false)
    private Date cUpdateTime;

    @JSONField(serialize = false)
    @TableField(exist = false)
    private String protocolFilter;

    @TableField(exist = false)
    List<Service> services;

}
